﻿<UserControl x:Class="AnthStat.WPF.Presentation.Controls.NutritionalSurveyView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="clr-namespace:AnthStat.WPF.Presentation.Controls"
             xmlns:p="clr-namespace:AnthStat.WPF.Presentation.Properties"
             xmlns:viewmodels="clr-namespace:AnthStat.WPF.Applications;assembly=AnthStat.WPF.Applications"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="400" d:DesignWidth="1100">
    <UserControl.Resources>
        <viewmodels:DesignProjectViewModel x:Key="DesignViewModel" />
    </UserControl.Resources>
    <Grid d:DataContext="{StaticResource DesignViewModel}">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid Grid.Row="0" Background="{StaticResource AccentDarkBrush}" Height="Auto">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            
            <StackPanel Orientation="Horizontal" Margin="0, 6, 0, 6">
                <StackPanel Width="20" />
                <Button Style="{StaticResource DarkButtonStyle}" Width="100" Command="{Binding AddPersonCommand}" IsEnabled="True" Background="{StaticResource AccentLightBrush}" Content="Add child" />
                <StackPanel Width="6" />
                <Button Style="{StaticResource DarkButtonStyle}" Width="100" Command="{Binding PromptRemovePersonCommand}" IsEnabled="True" Background="{StaticResource AccentLightBrush}" Content="Remove child" />
                <StackPanel Width="6" />
                <Button Style="{StaticResource DarkButtonStyle}" Width="100" Command="{Binding SaveCommand}" IsEnabled="True" Background="{StaticResource AccentLightBrush}" Content="Save" />
            </StackPanel>

            <StackPanel Grid.Column="1" VerticalAlignment="Center" Margin="0, 0, 10, 0" Orientation="Horizontal">
                <TextBlock Foreground="#EEF4FB" Text="{Binding ChildrenView.Count}" />
                <StackPanel Width="4" />
                <TextBlock Foreground="#EEF4FB" Text="records" />
            </StackPanel>
        </Grid>

        <Grid Grid.Row="1">
            
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid Grid.Column="0" Grid.RowSpan="2" Width="20">
                <Grid Width="4" HorizontalAlignment="Right" VerticalAlignment="Stretch">
                    <Grid.Background>
                        <LinearGradientBrush StartPoint="1,0" EndPoint="0,0">
                            <GradientStop Offset="0" Color="#CCCCCC" />
                            <GradientStop Offset="1" Color="Transparent" />
                        </LinearGradientBrush>
                    </Grid.Background>
                </Grid>
            </Grid>

            <DataGrid Grid.Column="1" 
                      RowHeight="30"
                      AutoGenerateColumns="False" 
                      ItemsSource="{Binding ChildrenView}" 
                      IsSynchronizedWithCurrentItem="True"
                      VirtualizingStackPanel.IsVirtualizing="True"
                      VirtualizingStackPanel.VirtualizationMode="Recycling">
                <DataGrid.Columns>

                    <DataGridTemplateColumn Header="Survey date">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <!--<DatePicker SelectedDate="{Binding MeasurementsView.CurrentItem.DateMeasurement, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" BorderBrush="Transparent" />-->

                                <Grid>
                                    <DatePicker SelectedDate="{Binding MeasurementsView.CurrentItem.DateMeasurement, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True}" BorderBrush="Transparent"
                                            Visibility="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGridCell}}, Converter={StaticResource BooleanToVisibilityConverter}}"/>

                                    <TextBlock Text="{Binding MeasurementsView.CurrentItem.DateMeasurement, StringFormat=d}" HorizontalAlignment="Left" Width="Auto" VerticalAlignment="Center" Margin="5, 0, 0, 0"
                                    Visibility="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGridCell}}, Converter={StaticResource BooleanToCollapsedConverter}}" />
                                </Grid>
                                
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
                    
                    <DataGridTextColumn Header="Id" IsReadOnly="True" Binding="{Binding NumericId}" Width="35" />
                    
                    <DataGridTextColumn Header="Team" Binding="{Binding Team, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
                    <DataGridTextColumn Header="Cluster" Binding="{Binding Cluster, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True, TargetNullValue=''}" />
                    <DataGridTextColumn Header="Household" Binding="{Binding Household, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True}" />
                    
                    <DataGridTextColumn Header="Last name" Binding="{Binding LastName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
                    <DataGridTextColumn Header="First name" Binding="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
                    <DataGridComboBoxColumn Header="Sex" ItemsSource="{StaticResource SexArray}" DisplayMemberPath="DisplayString" SelectedValuePath="ValueString" SelectedValueBinding="{Binding Sex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}"/>
                    <DataGridTemplateColumn Header="Date of birth">
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                
                                <Grid>
                                <DatePicker SelectedDate="{Binding DateBirth, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True}" BorderBrush="Transparent"
                                            Visibility="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGridCell}}, Converter={StaticResource BooleanToVisibilityConverter}}"/>

                                <TextBlock Text="{Binding DateBirth, StringFormat=d}" HorizontalAlignment="Left" Width="Auto" VerticalAlignment="Center" Margin="5, 0, 0, 0"
                                    Visibility="{Binding Path=IsSelected, RelativeSource={RelativeSource AncestorType={x:Type DataGridCell}}, Converter={StaticResource BooleanToCollapsedConverter}}" />
                                </Grid>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>

                    <DataGridCheckBoxColumn Binding="{Binding IsDateBirthEstimated, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}">
                        <DataGridCheckBoxColumn.HeaderTemplate>
                            <DataTemplate>
                                <TextBlock TextAlignment="Center">
                                    Date of birth<LineBreak/>is estimated
                                </TextBlock>
                            </DataTemplate>
                        </DataGridCheckBoxColumn.HeaderTemplate>
                    </DataGridCheckBoxColumn>

                    <DataGridTextColumn Header="Age (d)" Binding="{Binding MeasurementsView.CurrentItem.AgeDays, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=0}" />
                    <DataGridTextColumn IsReadOnly="True" Header="Age (mos)" Binding="{Binding MeasurementsView.CurrentItem.AgeMonths, Mode=OneWay,StringFormat=0.0}" />
                    <DataGridTextColumn IsReadOnly="True" Header="Age (yrs)" Binding="{Binding MeasurementsView.CurrentItem.AgeYears, Mode=OneWay,StringFormat=0.0}" />

                    <DataGridCheckBoxColumn Header="Recumbent" Binding="{Binding MeasurementsView.CurrentItem.IsRecumbent, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
                    <DataGridCheckBoxColumn Header="Oedema" Binding="{Binding MeasurementsView.CurrentItem.HasOedema, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnNotifyDataErrors=True}" />
                    <DataGridTextColumn Header="Height" Binding="{Binding MeasurementsView.CurrentItem.Height, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True, TargetNullValue=''}" />
                    <DataGridTextColumn Header="Weight" Binding="{Binding MeasurementsView.CurrentItem.Weight, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True, TargetNullValue=''}" />
                    <DataGridTextColumn IsReadOnly="True" Header="BMI" Binding="{Binding MeasurementsView.CurrentItem.BodyMassIndex, Mode=OneWay}" />
                    <DataGridTextColumn Header="HC" Binding="{Binding MeasurementsView.CurrentItem.HeadCircumference, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True, TargetNullValue=''}" />
                    <DataGridTextColumn Header="MUAC" Binding="{Binding MeasurementsView.CurrentItem.MidUpperArmCircumference, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True, TargetNullValue=''}" />
                    <DataGridTextColumn Header="SSF" Binding="{Binding MeasurementsView.CurrentItem.SubscapularSkinfold, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True, TargetNullValue=''}" />
                    <DataGridTextColumn Header="TSF" Binding="{Binding MeasurementsView.CurrentItem.TricepsSkinfold, Mode=TwoWay, UpdateSourceTrigger=LostFocus, ValidatesOnNotifyDataErrors=True, TargetNullValue=''}" />

                    <DataGridTextColumn IsReadOnly="True" Header="HAZ" Binding="{Binding MeasurementsView.CurrentItem.WHOHAZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="HAP" Binding="{Binding MeasurementsView.CurrentItem.WHOHAP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />

                    <DataGridTextColumn IsReadOnly="True" Header="WAZ" Binding="{Binding MeasurementsView.CurrentItem.WHOWAZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="WAP" Binding="{Binding MeasurementsView.CurrentItem.WHOWAP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />

                    <DataGridTextColumn IsReadOnly="True" Header="WHZ" Binding="{Binding MeasurementsView.CurrentItem.WHOWHZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="WHP" Binding="{Binding MeasurementsView.CurrentItem.WHOWHP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />

                    <DataGridTextColumn IsReadOnly="True" Header="BMIZ" Binding="{Binding MeasurementsView.CurrentItem.WHOBMIZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="BMIP" Binding="{Binding MeasurementsView.CurrentItem.WHOBMIP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />

                    <DataGridTextColumn IsReadOnly="True" Header="HCZ" Binding="{Binding MeasurementsView.CurrentItem.WHOHCZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="HCP" Binding="{Binding MeasurementsView.CurrentItem.WHOHCP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />

                    <DataGridTextColumn IsReadOnly="True" Header="MUACZ" Binding="{Binding MeasurementsView.CurrentItem.WHOMUACZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="MUACP" Binding="{Binding MeasurementsView.CurrentItem.WHOMUACP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />

                    <DataGridTextColumn IsReadOnly="True" Header="SSFZ" Binding="{Binding MeasurementsView.CurrentItem.WHOSSFZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="SSFP" Binding="{Binding MeasurementsView.CurrentItem.WHOSSFP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />

                    <DataGridTextColumn IsReadOnly="True" Header="TSFZ" Binding="{Binding MeasurementsView.CurrentItem.WHOTSFZ, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />
                    <DataGridTextColumn IsReadOnly="True" Header="TSFP" Binding="{Binding MeasurementsView.CurrentItem.WHOTSFP, Mode=OneWay, TargetNullValue='', StringFormat=0.00}" />



                </DataGrid.Columns>
            </DataGrid>
            
            <Border Grid.Row="2" Grid.Column="1" Padding="20, 5, 0, 15" BorderThickness="0, 1, 0, 0" BorderBrush="Silver">

                <controls:IndicatorOutputsWHO Style="{StaticResource HorizontalWHOIndicatorsStyle}" DataContext="{Binding ChildrenView.CurrentItem.MeasurementsView.CurrentItem}" />
            </Border>

        </Grid>
    </Grid>
</UserControl>
